<!DOCTYPE HTML>
<html>
<head>
    <title>Error</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body>
<div style="margin: 0 auto">
    <div id="form1">
        <span style="width:80px;display:inline-block;">用户名称：</span>
        <input id="name" class="mini-textbox" style="width:155px;" required="true" value="<%= result.data[0].name%>"/>

        <span style="width:80px;display:inline-block;">用户状态：</span>
        <input id="status" class="mini-combobox" style="width:155px;" data="userStatus" value="<%= result.data[0].status%>"/>
        <br/><br/>

        <span style="width:80px;display:inline-block;">身份证号码：</span>
        <input id="idCard" class="mini-textbox" style="width:155px;"  value="<%= result.data[0].idCard%>" />

        <span style="width:80px;display:inline-block;">用户级别：</span>
        <input id="level" class="mini-combobox" style="width:155px;" data="<%= result.levelTree%>" value="<%= result.data[0].levelOId%>"  />

        <br/><br/>

        <span style="width:80px;display:inline-block;">微信号：</span>
        <input id="weChat" class="mini-textbox" style="width:155px;" value="<%= result.data[0].weChat%>"/>

        <span style="width:80px;display:inline-block;">电话号码：</span>
        <input id="telephone" class="mini-textbox" style="width:155px;" value="<%= result.data[0].telephone%>"/>

        <br/><br/>

        <span style="width:80px;display:inline-block;">团队长：</span>
        <input id="teamLeader" class="mini-textbox" style="width:155px;" value="<%= result.data[0].teamLeader%>"/>

        <br/><br/>

        <span style="width:120px;display:inline-block;">授权开始时间：</span>
        <input id="startPowerTime" class="mini-datepicker" style="width:200px;" onvaluechanged="onValueChang" value="<%= result.data[0].startPowerTime%>"
               format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" showOkButton="true" showClearButton="false"/>

        <br /><br />

        <span style="width:120px;display:inline-block;">授权结束时间：</span>
        <input id="endPowerTime" class="mini-datepicker" style="width:200px;" onvaluechanged="onValueChanged" value="<%= result.data[0].endPowerTime%>"
               format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" showOkButton="true" showClearButton="false"/>

        <br /><br />
    </div>

    <div style="margin: 0 auto;text-align: center">
        <a class="mini-button " iconCls="icon-ok" onclick="updataUser()">确定</a>
        <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
    </div>
</div>
</body>
<script>
    var userStatus = [{ id: 1, text: '正常' }, { id: 0, text: '关闭'}];
    var objectId = '<%= result.data[0].objectId%>';
    function updataUser() {
        var name = mini.get("name").getValue();
        var status = mini.get("status").getValue();
        var idCard = mini.get("idCard").getValue();
        var level = mini.get("level").getValue();
        var weChat = mini.get("weChat").getValue();
        var telephone = mini.get("telephone").getValue();
        var startPowerTime = mini.get("startPowerTime").getValue();
        var endPowerTime = mini.get("endPowerTime").getValue();
        var teamLeader = mini.get("teamLeader").getValue();
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) return;
        form.loading("生成授权证书中");
        $.ajax({
            type: "POST",
            url: "/getdata/editUserInformation",
            data: {
                objectId:objectId,
                name: name,
                status: status,
                idCard: idCard,
                level: level,
                weChat: weChat,
                telephone:telephone,
                startPowerTime:startPowerTime,
                endPowerTime:endPowerTime,
                teamLeader:teamLeader
            },
            success: function (result) {
                console.log(result);
                if (result=='10000'){
                    CloseWindow("save")
                }else {
                    alert("服务器错误，证书生成失败");
                    CloseWindow("save")
                };
            }
        })
    }
    //    关闭窗口
    function CloseWindow(action) {
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }
    function onOk(e) {
        SaveData();
    }
    function onCancel(e) {
        CloseWindow("cancel");
    }
    function onValueChanged() {
        var startPowerTime = Date.parse(mini.get("startPowerTime").getValue());
        var endPowerTime = Date.parse(mini.get("endPowerTime").getValue());
        var end = mini.get("endPowerTime");
        if (startPowerTime=""||endPowerTime<startPowerTime){
            alert("请先输入授权开始时间，授权结束时间必须大于开始时间")
            end.setValue('');
        }
    }

</script>
</html>